package com.shuai.chatroom.service;

import com.shuai.chatroom.entity.FriendApplyInfo;
import com.shuai.chatroom.entity.vo.FriendApplyInfoVO;
import com.shuai.chatroom.mapper.FriendApplyMapper;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class FriendApplyService {
    @Resource
    private FriendApplyMapper friendApplyMapper;

    /**
     * 向表中添加 --好友验证消息
     */
    public int addApply(FriendApplyInfo friendApplyInfo) {
        return friendApplyMapper.addApply(friendApplyInfo);
    }

    /**
     * 删除数据库表中的某条验证消息
     */
    public int delApply(Integer uId, Integer applyId) {
        return friendApplyMapper.delApply(uId, applyId);
    }

    /**
     * 根据用户id返回表中的好友申请信息
     */
    public List<FriendApplyInfoVO> getApplies(Integer uId) {
        return friendApplyMapper.getApplies(uId);
    }

    /**
     * 根据验证消息编号返回发送反正消息人的用户名和头像
     */
    public FriendApplyInfoVO getApplyVO(Integer applyId) {
        return friendApplyMapper.getApplyVO(applyId);
    }


    /**
     * 根据发送者和接受者判断这条验证消息是否已经发送过了
     */
    public boolean isSend(Integer fromUId, Integer toUId) {
        return friendApplyMapper.isSend(fromUId, toUId) > 0;
    }
}
